from convdiffproblembase import ConvDiffProblemBase
from dolfin import *
from math import pi, cos, sin

class Knobloch1(ConvDiffProblemBase):
    '''Convection-Diffusion problem with exponential boundary layers and interior layer.'''
    def __init__(self,eps=1E-7,N=20):
        self.name = 'K1'
    
        self.mesh = UnitSquare(N,N,'left')
        self.eps = Constant(eps)
        self.BCValues = [Constant(0.), Constant(1.)]
        self.b = Constant((cos(-pi/3.),sin(-pi/3.)))
        self.f = Constant(0.)
        self.BCIndicators = [Knobloch1.boundary0.__func__, Knobloch1.boundary1.__func__]

    def boundary0(x, on_boundary):
        return on_boundary and ( ( abs(x[0]-1) < DOLFIN_EPS ) or ( x[1] <= 0.7 ) )
    
    def boundary1(x, on_boundary):
        return on_boundary and not( ( abs(x[0]-1) < DOLFIN_EPS ) or ( x[1] <= 0.7 ) )
